#include "widget.h"
#include "ui_widget.h"
#include <QTimer>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //设置初始值
    ui->lcdNumber->display(10);

    timer = new QTimer(this);
    //timeout信号绑定槽函数
    connect(timer,&QTimer::timeout,this,&Widget::handle);
    //设置每隔几秒发送信号
    timer->start(1000);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::handle()
{
    //先获取当前的值
    int value = ui->lcdNumber->intValue();
    if(value <= 0)
    {
        timer->stop();
    }
    else
    {
        ui->lcdNumber->display(value -1);
    }
}

